from django.shortcuts import render,redirect,HttpResponse
from first_app.ana import Chipo
from django import views


REMOTE_HOST = "https://pyecharts.github.io/assets/js"


def index(request):
    return render(request, "first_app/index.html")



def chipo_home(request):
    return render(request,"first_app/chipo_home.html")



def ana_one(request):

    x = Chipo().Total_sales_of_the_restaurant()
    ti = "1.这段时间内餐厅的销售流水总额"

    con = {
        "x": x,
        "ti": ti
    }

    return render(request, "first_app/ana_1.html", context=con)


def ana_two(request):

    x = Chipo().The_largest_number_of_items_sold()
    ti = '2.这段时间内销售个数最多的商品'
    con = {
        "x": x,
        "ti": ti
    }

    return render(request, "first_app/ana_1.html", context=con)

def ana_three(request):

    x = Chipo().most_money_com()

    ti = '3.这段时间内销售金额最多的商品'
    con = {
        "x": x,
        "ti": ti
    }

    return render(request, "first_app/ana_1.html", context=con)


def ana_four(request):

    bar = Chipo().each_com_number_bar()

    context = {
        'myechart': bar.render_embed(),
        'host': REMOTE_HOST,
        'script_list': bar.get_js_dependencies(),
        'ti': "4.每种商品的销售个数，并做图"
        }
    return render(request, "first_app/data.html", context)


def ana_five(request):

    bar = Chipo().each_com_money_bar()

    context = {
        'myechart': bar.render_embed(),
        'host': REMOTE_HOST,
        'script_list': bar.get_js_dependencies(),
        'ti': "5.每种商品的销售金额，并做图"
    }
    return render(request, "first_app/data.html", context)


def ana_six(request):

    p = HttpResponse()

    f = open(r'C:\Users\关亮亮\Desktop\guan_week_data\guan_data_project\first_app\price.xlsx', 'rb')  # 打开文件

    p.content = f

    p["Content_Type"] = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"  # Content_Type  类型

    p['Content-Disposition'] = 'attachment;filename="price.xlsx"'

    return p




def ana_seven(request):

    pie = Chipo().each_com_all_money_ratio_pie()

    context = {
        'myechart': pie.render_embed(),
        'host': REMOTE_HOST,
        'script_list': pie.get_js_dependencies(),
        'ti': "7.每种商品销售金额在流水总额中所占的比例，做圆饼图"
    }
    return render(request, "first_app/data.html", context)


def ana_eight(request):

    pie = Chipo().each_order_id_bar()

    context = {
        'myechart': pie.render_embed(),
        'host': REMOTE_HOST,
        'script_list': pie.get_js_dependencies(),
        'ti': "8.每个定单金额，并做bar图"
    }
    return render(request, "first_app/data.html", context)


def ana_nine(request):

    x = Chipo().chicken_bowl_toppings()

    ti = "9.产品“Chicken Bowl”,选择最多的配料"

    con = {
        "x": x,
        "ti": ti
    }

    return render(request, "first_app/ana_1.html", context=con)


def ana_ten(request):

    pie = Chipo().chicken_bowl_number_pie()

    context = {
        'myechart': pie.render_embed(),
        'host': REMOTE_HOST,
        'script_list': pie.get_js_dependencies(),
        'ti': "10.产品“Chicken Bowl”每种配料选择的次数，及所占比例，并做圆饼图"
    }
    return render(request, "first_app/data.html", context)